package com.jiang.jixiang.ui;


import android.os.Bundle;

import androidx.recyclerview.widget.LinearLayoutManager;

import com.jiang.jixiang.R;
import com.jiang.jixiang.api.ApiUrl;
import com.jiang.jixiang.bean.UsingHelpBean;
import com.jiang.jixiang.databinding.ActivityUsinghelpBinding;
import com.jiang.jixiang.network.CommonalityModel;
import com.jiang.jixiang.network.NetWorkListener;
import com.jiang.jixiang.network.okHttpModel;
import com.jiang.jixiang.ui.adapter.UsingHelpAdapter;
import com.ws.universal.tools.base.BaseActivity;
import com.ws.universal.tools.base.ManageActivity;
import com.ws.universal.tools.utils.GsonUtils;
import com.ws.universal.tools.utils.ToastUtils;

import org.json.JSONObject;

/**
 * 使用帮助
 */
public class UsingHelpActivity extends BaseActivity implements NetWorkListener {
    private ActivityUsinghelpBinding binding;
    private UsingHelpAdapter usingHelpAdapter;
    private UsingHelpBean usingHelpBean;

    @Override
    protected void initCreate(Bundle savedInstanceState) {
        ManageActivity.putActivity(this.getClass().getSimpleName(), this);
        binding = ActivityUsinghelpBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());
    }

    @Override
    protected void initView() {
        binding.inTitle.titleTextTv.setText(R.string.using_help);
        binding.inTitle.titleLeftBtn.setOnClickListener(view -> {
            finish();
        });
        LinearLayoutManager manager = new LinearLayoutManager(getContext());
        manager.setOrientation(LinearLayoutManager.VERTICAL);
        binding.reyData.setLayoutManager(manager);

        usingHelpAdapter = new UsingHelpAdapter();
        binding.reyData.setAdapter(usingHelpAdapter);
        loadData();

//        binding.expandableTextView.setTitle("测试");
//        binding.expandableTextView.setText("Regarding the costFlutter这门新技术也逐渐\n进入了移动开发者的视野，尤其是当Google在2018年IO大会上发布了第一个Preview版本后，国内刮起来一股学习Flutter的热潮。\n\n为了更好的方便帮助中国开发者了解这门新技术，我们，Flutter中文网，前后发起了Flutter翻译计划、Flutter开源计划，前者主要的任务是翻译" +
//                "Flutter官方文档，后者则主要是开发一些常用的包来丰富Flutter生态，帮助开发者提高开发效率。而时" +
//                "至今日，这两件事取得的效果还都不错！"
//        );


    }

    private void loadData() {

        okHttpModel.post(ApiUrl.faqList_Api, null, ApiUrl.faqList_Api_ID, this);
    }


    @Override
    public void onSucceed(JSONObject jsonData, int id, CommonalityModel commonality) {
        JSONObject data = jsonData.optJSONObject("data");
        switch (id) {
            case ApiUrl.faqList_Api_ID:
                usingHelpBean = GsonUtils.parseJObject(data.toString(), UsingHelpBean.class);
                usingHelpAdapter.setList(usingHelpBean.getList());
                break;
        }

    }

    @Override
    public void onFail(JSONObject jsonData, int id, CommonalityModel commonality) {
        stopProgressDialog();
        ToastUtils.showShort(commonality.getMessage());
    }

    @Override
    public void onError(int id, Exception e) {
        stopProgressDialog();
        ToastUtils.showShort(e.getMessage());
    }


    @Override
    protected void FinishDesTroy() {

        ManageActivity.removeActivity(this.getClass().getSimpleName());
    }

}
